package com.mashang.bookkeepingbook.controller;

import com.mashang.bookkeepingbook.pojo.entity.Result;
import com.mashang.bookkeepingbook.pojo.entity.User;
import com.mashang.bookkeepingbook.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController

public class LoginController {
    @Autowired
    private LoginService loginService;
    @PostMapping("/user/login")
    public Result login(@Param("username") String username,@Param("password") String password)
    {
        //todo 后续用jwt验证
        log.info("用户名：{}，密码：{}", username, password);
        User user = loginService.login(username, password);
        if(user != null)
        {
            return Result.Success(user);
        }
        else
        {
            return Result.Fail("用户名或密码错误");
        }
    }
}
